//
//  ServiceDetailViewController.m
//  cityStar
//
//  Created by joyban on 14-12-26.
//  Copyright (c) 2014年 tiny. All rights reserved.
//

#import "ServiceDetailViewController.h"
#import "StayViewController.h"
#import "UIColor+FlatUI.h"
#import "RIButtonItem.h"
#import "UIAlertView+Blocks.h"

#import "CommunityDetailTwoCell.h"
#import "goodsDetailCell.h"
#import "ContentCell.h"
#import "AddressCell.h"
#import "webView.h"
#import "CollectionCell.h"

NSString *const ServiceDetailTwoCellID = @"serviceDetailTwoCellID";
NSString *const ServiceTableViewCellID = @"serviceCellID";
NSString *const ServiceAddressCellID = @"serviceAddressCellID";
NSString *const ServiceContentCellID = @"servicecontentCellID";
NSString *const CollectionServiceTableViewCellID = @"collectionServiceCellID";

@interface ServiceDetailViewController ()<CSbtnDelegate,CSAddressDelegate,CSgoodsDelegate>

@property (weak, nonatomic) IBOutlet UITableView *SevicetableView;
@property (weak,nonatomic) NSString *status;
@property (strong,nonatomic) goodsDetailCell *ServiceetailCell;

@end

@implementation ServiceDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"服务详情";
    [self addBackButton];
    self.status = @"YES";
    [self setUpTableViews];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - collectionCell btndelegate
//4张图片
-(void)senderBtnClick:(UIButton *)btn
{
    
}
//收藏
-(void)sendergoodsClick:(UIButton *)btn
{
    if([self.status isEqualToString:@"YES"])
    {
        [SVProgressHUD showSuccessWithStatus:@"收藏成功"];
        [self.ServiceetailCell.Collectionbtn setImage:[UIImage imageNamed:@"collection_y"] forState:UIControlStateNormal];
        self.status = @"NO";
    }else{
        [SVProgressHUD showSuccessWithStatus:@"取消收藏"];
        [self.ServiceetailCell.Collectionbtn setImage:[UIImage imageNamed:@"collection_n"] forState:UIControlStateNormal];
        self.status = @"YES";
    }
    
}
//打电话
-(void)senderContactClick:(NSString *)telNum
{
    
    
    RIButtonItem *leftButton = [RIButtonItem itemWithLabel:@"确定" action:^{
        NSString *telStr=[@"tel://" stringByAppendingString:[NSString stringWithFormat:@"%@",telNum]];
        NSURL *url=[NSURL URLWithString:telStr];
        [[UIApplication sharedApplication]openURL:url];
    }];
    RIButtonItem *rightButton = [RIButtonItem itemWithLabel:@"取消"];
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"是否拨打该号码？" message:telNum cancelButtonItem:rightButton otherButtonItems:leftButton, nil];
    [alertView show];
}
//进入商铺
-(void)senderintoactClick:(UIButton *)btn
{
    
}

-(void)setUpTableViews
{
    [self.SevicetableView registerNib:[CommunityDetailTwoCell nib] forCellReuseIdentifier:ServiceDetailTwoCellID];
    [self.SevicetableView registerNib:[goodsDetailCell nib] forCellReuseIdentifier:ServiceTableViewCellID];
    [self.SevicetableView registerNib:[ContentCell nib] forCellReuseIdentifier:ServiceContentCellID];
    [self.SevicetableView registerNib:[CollectionCell nib] forCellReuseIdentifier:CollectionServiceTableViewCellID];
    [self.SevicetableView registerNib:[AddressCell nib] forCellReuseIdentifier:ServiceAddressCellID];
}
#pragma mark - UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
    {
        if(indexPath.row == 0)
        {
            return [goodsDetailCell heightOfTableCell];
        }else if (indexPath.row == 2)
        {
            return [ContentCell heightOfTableCell];
        }else{
            return [CommunityDetailTwoCell heightOfTableCell];
        }
    }else if(indexPath.section == 1)
    {
        return [AddressCell heightOfTableCell];
    }else{
        return [CollectionCell heightOfTableCell];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 2)
    {
        return 30;
    }else{
        return 0;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if(section == 2)
    {
        return 0;
    }else{
        return 15;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section == 0)
    {
        return 3;
    }else{
        return 1;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView * sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 220)] ;
    [sectionView setBackgroundColor:[UIColor colorFromHexCode:@"F6F5F1"]];
    return sectionView;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIImageView *imageOne = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 1)];
    [imageOne setBackgroundColor:[UIColor colorFromHexCode:@"ECECEC"]];
    
    UIImageView *imageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(0, 29, tableView.bounds.size.width, 1)];
    [imageTwo setBackgroundColor:[UIColor colorFromHexCode:@"ECECEC"]];
    
    UILabel * label = [[UILabel alloc] init] ;
    label.frame = CGRectMake(15, 5, 200, 20);
    label.backgroundColor = [UIColor clearColor];
    label.font=[UIFont fontWithName:@"Helvetica-Bold" size:14];
    
    UIView * sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 220)] ;
    [sectionView setBackgroundColor:[UIColor colorFromHexCode:@"EEEEEE"]];
    [sectionView addSubview:label];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 5, 20, 20)];
    [imageView setImage:[UIImage imageNamed:@"recom"]];
    [sectionView addSubview:imageView];
    [sectionView addSubview:imageOne];
    [sectionView addSubview:imageTwo];
    
    [label setFrame:CGRectMake(45, 5, 200, 20)];
    label.textColor = [UIColor colorFromHexCode:@"8E8E8E"];
    label.text = @"到过这里的人还看过";
    
    return sectionView;
}

#pragma mark - UITableViewDataSource
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
    {
        if(indexPath.row == 0)
        {
            self.ServiceetailCell = [tableView dequeueReusableCellWithIdentifier:ServiceTableViewCellID];
            self.ServiceetailCell.selectionStyle = UITableViewCellSelectionStyleNone;
            self.ServiceetailCell.delegate = self;
            return self.ServiceetailCell;
        }else if(indexPath.row == 2){
            ContentCell *contentCell = [tableView dequeueReusableCellWithIdentifier:ServiceContentCellID];
            contentCell.selectionStyle = UITableViewCellSelectionStyleNone;
            return contentCell;
        }else{
            CommunityDetailTwoCell *ServiceDetailTwoCell = [tableView dequeueReusableCellWithIdentifier:ServiceDetailTwoCellID];
            ServiceDetailTwoCell.selectionStyle = UITableViewCellSelectionStyleNone;
            [ServiceDetailTwoCell.heardImage setImage:[UIImage imageNamed:@"list_tel"]];
            ServiceDetailTwoCell.contentLabel.text = @"167298238923";
            return ServiceDetailTwoCell;
        }
        
    }else if(indexPath.section == 1)
    {
        AddressCell *ServiceaddressCell = [tableView dequeueReusableCellWithIdentifier:ServiceAddressCellID];
        ServiceaddressCell.selectionStyle = UITableViewCellSelectionStyleNone;
        ServiceaddressCell.delegate = self;
        return ServiceaddressCell;
    }else{
        CollectionCell *collectionServiceCell = [tableView dequeueReusableCellWithIdentifier:CollectionServiceTableViewCellID];
        collectionServiceCell.delegate = self;
        collectionServiceCell.selectionStyle = UITableViewCellSelectionStyleNone;
        return collectionServiceCell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
    {
        if(indexPath.row == 1)
        {
            RIButtonItem *leftButton = [RIButtonItem itemWithLabel:@"确定" action:^{
                NSString *telStr=[@"tel://" stringByAppendingString:@"167298238923"];
                NSURL *url=[NSURL URLWithString:telStr];
                [[UIApplication sharedApplication]openURL:url];
            }];
            RIButtonItem *rightButton = [RIButtonItem itemWithLabel:@"取消"];
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"是否拨打该号码？" message:@"167298238923" cancelButtonItem:rightButton otherButtonItems:leftButton, nil];
            [alertView show];
        }
        if(indexPath.row == 2)
        {
            webView *webViewController = [[webView alloc]init];
            webViewController.navTitle = @"商品名称";
            [self.navigationController pushViewController:webViewController animated:YES];
        }
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
